;NSIS Script

;Title Of Your Application
Name "Code Helper"
!define company "Immensetech"
BrandingText "Immensetech"

;Do A CRC Check
CRCCheck On

;Make uninstall to remove Start Menu icons
RequestExecutionLevel highest

;Output File Name
OutFile "code-helper-0.3-win64.exe"

;The Default Installation Directory
InstallDir "$PROGRAMFILES64\Immensetech\CodeHelper"

;The text to prompt the user to enter a directory
DirText "Please select the folder below"

Function .onInit
  System::Call "kernel32::GetCurrentProcess() i .s"
  System::Call "kernel32::IsWow64Process(i s, *i .r0)"
  IntCmp $0 0 init32bits
  Goto init64bits
init32bits:
  Messagebox MB_OK "Sorry, this installer is for 64-bit Windows. Please download the version match your platform."
  Abort
init64bits:
FunctionEnd

Section "Install"
  ;Install Files
  SetOutPath $INSTDIR
  SetCompress Auto
  SetOverwrite IfNewer
  File /oname=CodeHelper.exe "dist\App1.exe"
  File "dist\*.pyd"
  File "dist\*.dll"
  File "dist\*.ico"
  File "dist\*.zip"

  ; Write the uninstall keys for Windows
  WriteRegStr HKLM "Software\Microsoft\Windows\CurrentVersion\Uninstall\CodeHelper" "DisplayName" "CodeHelper (remove only)"
  WriteRegStr HKLM "Software\Microsoft\Windows\CurrentVersion\Uninstall\CodeHelper" "UninstallString" "$INSTDIR\Uninst.exe"
WriteUninstaller "Uninst.exe"
SectionEnd

Section "Shortcuts"
  ;Add Shortcuts
  CreateDirectory "$SMPROGRAMS\Immensetech\Code Helper"
  CreateShortCut "$SMPROGRAMS\Immensetech\Code Helper\Code Helper.lnk" "$INSTDIR\CodeHelper.exe" "" "$INSTDIR\CodeHelper.exe" 0
  CreateShortCut "$SMPROGRAMS\Immensetech\Code Helper\Uninstall Code Helper.lnk" "$INSTDIR\Uninst.exe" "" "$INSTDIR\Uninst.exe" 0
  CreateShortCut "$DESKTOP\Code Helper.lnk" "$INSTDIR\CodeHelper.exe" "" "$INSTDIR\CodeHelper.exe" 0
SectionEnd

UninstallText "This will uninstall Code Helper from your system"

Section Uninstall
  ;Delete Files
  Delete "$INSTDIR\*.*"
  RmDir "$INSTDIR"
  Delete "$DESKTOP\Code Helper.lnk"

  ;Delete Start Menu Shortcuts
  Delete "$SMPROGRAMS\Immensetech\Code Helper\*.*"
  RmDir "$SMPROGRAMS\Immensetech\Code Helper"

  ;Delete Uninstaller And Unistall Registry Entries
  Delete "$INSTDIR\Uninst.exe"
  DeleteRegKey HKEY_LOCAL_MACHINE "SOFTWARE\CodeHelper"
  DeleteRegKey HKEY_LOCAL_MACHINE "SOFTWARE\Microsoft\Windows\CurrentVersion\Uninstall\CodeHelper"
  RMDir "$INSTDIR"
SectionEnd